<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>

<script>
    import { createStore, createLogger } from 'vuex'
    const env = process.env.NODE_ENV
    const store = createStore({
        state: {
            x: 0,
            y: 0
        },
        mutations: {
            changX(state, payload = 1) {
                state.x = payload
            },
            changY(state, payload = 1) {
                state.y = payload
            }
        },
        actions: {
            changYAsync({ commit }, payload) {
                setTimeout(() => {
                    commit('changY', payload)
                }, 1000)
            }
        },
        plugins: env === 'production' ? [] : [createLogger()]
    })
</script>


<script setup>
    import { useStore } from 'vuex'
    // mapState 辅助函数不好用。
    const store1 = useStore()
    // store.commit('xxx')
    // store.dispatch('xxx')
    // 
</script>
</html>